/*
 * spinlockacquire.{cc,hh} -- element acquires spinlock
 * Benjie Chen
 *
 * Copyright (c) 1999-2000 Massachusetts Institute of Technology.
 *
 * This software is being provided by the copyright holders under the GNU
 * General Public License, either version 2 or, at your discretion, any later
 * version. For more information, see the `COPYRIGHT' file in the source
 * distribution.
 */

#include <click/config.h>
#include <click/router.hh>
#include <click/confparse.hh>
#include <click/error.hh>
#include "spinlockinfo.hh"
#include "spinlockacquire.hh"
CLICK_DECLS

int
SpinlockAcquire::configure(Vector<String> &conf, ErrorHandler *errh)
{
    String name;
    if (cp_va_kparse(conf, this, errh, "LOCK", cpkP+cpkM, cpString, &name, cpEnd)<0)
	return -1;
    for (int i = 0; i < router()->nelements(); i++) {
	if (SpinlockInfo *si = 
	    (SpinlockInfo *)(router()->element(i)->cast("SpinlockInfo"))) {
	    _lock = si->query(name, Element::name());
	    if (!_lock)
		return errh->error("cannot locate spinlock %s",name.c_str());
	    break;
	}
    }
    return 0;
}

CLICK_ENDDECLS
EXPORT_ELEMENT(SpinlockAcquire)
